Skip to content

Conversation

snitish
Copy link
Member

@snitish snitish commented Mar 13, 2025

When indexing a Period block, the BaseBlockManager.reindex_indexer method thinks Period blocks can't store 2D values and always returns the first element. This is because it uses a hardcoded list of types (which is missing PeriodDtype) that are known to allow 2D values. The fix is to use the is_1d_only_ea_dtype utility function which internally uses the _supports_2d flag of the dtype.

The bug only happens when indexing a 2D period block, which may be created after operations like transpose, pivot, unstack etc.

@mroeschke mroeschke requested a review from jbrockmendel March 13, 2025 02:14
@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type labels Mar 13, 2025
Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mroeschke mroeschke added this to the 3.0 milestone Mar 17, 2025
@mroeschke mroeschke merged commit 71e6166 into pandas-dev:main Mar 17, 2025
48 checks passed
@mroeschke
Copy link
Member

Thanks @snitish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: invalid result of reindex on columns after unstack with Period data BUG: period[h] + column splicing is not work

3 participants